import 'dart:io';

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:xiaomi_shop/app/modules/cart/views/cart_view.dart';
import 'package:xiaomi_shop/app/modules/category/views/category_view.dart';
import 'package:xiaomi_shop/app/modules/home/views/home_view.dart';
import 'package:xiaomi_shop/app/modules/service/views/service_view.dart';
import 'package:xiaomi_shop/app/modules/user/views/user_view.dart';

class TabsController extends GetxController {
  RxInt currentIndex = 0.obs;
  PageController pageController = Get.arguments != null
      ? PageController(initialPage: Get.arguments["currentPage"])
      : PageController(initialPage: 0);
  final List<Widget> pages = const [
    HomeView(),
    CategoryView(),
    ServiceView(),
    CartView(),
    UserView()
  ];
  @override
  void onInit() {
    super.onInit();
    if (kReleaseMode) {
      print("生成环境");
    } else if (kDebugMode) {
      print("开发环境");
    }

    if (Platform.isAndroid) {
      print("安卓");
    } else if (Platform.isIOS) {
      print("IOS");
    }

    configureRefresh();
    if (Get.arguments != null) {
      currentIndex.value = Get.arguments["currentPage"];
    }
  }

  configureRefresh() {
    EasyRefresh.defaultHeaderBuilder = () => const ClassicHeader(
          dragText: '下拉刷新',
          armedText: '松开刷新',
          readyText: '刷新中...',
          processingText: '刷新中...',
          processedText: '刷新成功',
          noMoreText: '没有更多数据',
          failedText: '加载失败',
          messageText: '上次更新时间 %T',
        );
    EasyRefresh.defaultFooterBuilder = () => const ClassicFooter(
          dragText: '上拉加载更多',
          armedText: '松开加载',
          readyText: '加载中...',
          processingText: '加载中...',
          processedText: '加载成功',
          noMoreText: '没有更多数据',
          failedText: '加载失败',
          messageText: '上次更新时间 %T',
        );
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void setCurrentIndex(int index) {
    currentIndex.value = index;
  }
}
